﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;

namespace library 
{
    public class Utility
    {

        //static System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer(); 

        public static int RandomNumber(int min, int max)
        {
            //Random(seed) uses the DateTime ticks to make it unique
            Random random = new Random((int)DateTime.Now.Ticks);
            return random.Next(min, max);
        }

        public static bool NumberRangeValidator(int min, int max, string strNumberToCheck)
        {
            try
            {
                int numberEntered = int.Parse(strNumberToCheck);
                if (numberEntered < min || numberEntered > max)
                    return true;
            }
            catch (FormatException)
            {
                return true;
            }
            return false;

        }

        public static bool MaxRangeValue(int max, string strNumberToCheck)
        {
            try
            {
                int numberEntered = int.Parse(strNumberToCheck);
                if (numberEntered > max)
                    return true;
            }
            catch (FormatException)
            {
                return true;
            }
            return false;
        }

        //private void Form1_Load(object sender, EventArgs e)
        //{
        //    myTimer.Tick += new EventHandler(timerRun);  //Method timerRun to be run
        //    myTimer.Interval = 1000;   //Sets the event to happen every second
        //    myTimer.Start();    //Starts the timer event
        //}

        //private void timerRun(object source, EventArgs myEventArgs)
        //{
        //    myTimer.Stop();  //Stop the timer
        //    string cwd = System.IO.Directory.GetCurrentDirectory(); //Get the current working direction 
        //    cwd = cwd.Replace("\\DrivingSystem\\bin\\Debug", "");  //Modify the path 
        //    UserHealth US_Obj1 = new UserHealth();  //Create the object to move the XML data into 
        //    try
        //    {
        //        XmlReader reader = new XmlTextReader(cwd + "\\Project_Files\\UserSystem.xml");  //Location and XML file to read in 
        //        XmlSerializer serializer = new XmlSerializer(typeof(UserHealth));  //typeof must be the same type(class) used to serialize the XML file
        //        US_Obj1 = (UserHealth)serializer.Deserialize(reader);  //Deserialize XML file back into that Object type
        //        reader.Close();  //Make sure to close the file read
        //    }
        //    catch (Exception ex)
        //    {
        //        //Write to log file
        //    }
        //    //Assign the object properties to the Window form textboxes
        //    txtBoxModel.Text = US_Obj1.Model;
        //    txtBoxHR.Text = US_Obj1.Heart_rate.ToString();
        //    txtBoxAge.Text = US_Obj1.Age.ToString();
        //    txtBoxHeight.Text = US_Obj1.Height.ToString();
        //    txtBoxWeight.Text = US_Obj1.Weight.ToString();
        //    myTimer.Start(); //Start the timer again
        //}



    }
}
